/**
 * @date 2006-9-11
 */

package org.nanhill.commons.model.pagination;

import java.util.Iterator;

/**
 * Abstract pagination model, defined by page size, page id, item count.
 * 
 * @author alin [xalinx at gmail dot com]
 * @date 2006-9-11
 */
public class Pagination<E> implements Paginable<E> {

	/**
	 * Items count.
	 */
	protected long count;

	/**
	 * Every page size.
	 */
	protected int pageSize;

	/**
	 * Page id.
	 */
	protected int pageId;

	/**
	 * Pages array.
	 */
	protected Iterator<E> pages;

	public long getCount() {
		return count;
	}

	public void setCount(long count) {
		this.count = count;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageId() {
		return pageId;
	}

	public void setPageId(int pageId) {
		this.pageId = pageId;
	}

	public void setPages(Iterator<E> pages) {
		this.pages = pages;
	}

	public Iterator<E> getPages() {
		return pages;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.nanhill.commons.model.pagination.Paginable#getPageCount()
	 */
	public int getPageCount() {
		int pageCount = (int)count / pageSize;
		pageCount = 0 == count % pageSize ? pageCount : pageCount + 1;
		return pageCount;
	}

}
